package com.karina.visualization.chart.component;

import com.karina.visualization.chart.model.CoordinateChartModel;
import com.karina.visualization.chart.skins.ChartPaneSkin;
import com.karina.visualization.chart.skins.CoordinatePaneSkinImpl;

public abstract class CoordinateChartWidget<Model extends CoordinateChartModel<DataType>, DataType>
		extends ChartWidgetBase<Model, DataType> {

	@SuppressWarnings({ "rawtypes", "unchecked" })
	public CoordinateChartWidget(CoordinateChart chart) {
		super(chart);
	}

	@Override
	public ChartPaneSkin<Model> getSkin() {
		return new CoordinatePaneSkinImpl(true);
	}

	public void setXSeriesProperty(final String xproperty) {

		if (getDataDescriptor() == null) {
			setDataDescriptor(new DefaultCategoryDataDescriptor(xproperty));
		}
		if (getData() != null) {
			getData().setDataDescriptor(getDataDescriptor());
			chart.caculateSeries();
		}
	}

	public void setOrigionalXY(int x, int y) {
		((CoordinateChart<Model, DataType>) chart).setOrigionalXY(x, y);
	}

	/**
	 * 
	 * 
	 * 
	 */
	@Override
	protected void setData(Model data) {

		super.setData(data);
		XAxis xaxis = ((CoordinateChart<Model, DataType>) chart).getXaxis();
		if (xaxis == null) {
			xaxis = new XAxis(data.getXAxisModel());
		} else {
			xaxis.setData(data.getXAxisModel());
		}
		((CoordinateChart<Model, DataType>) chart).setXaxis(xaxis);

		YAxis yaxis = ((CoordinateChart<Model, DataType>) chart).getYaxis();
		if (yaxis == null) {
			yaxis = new YAxis(data.getYAxisModel());
		} else {
			yaxis.setData(data.getYAxisModel());
		}
		((CoordinateChart<Model, DataType>) chart).setYaxis(yaxis);

	}
}
